package org.nstack.header.vm;

import org.nstack.header.host.HostVO;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.rest.RestRequest;
import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.notification.ApiNotification;


@Action(category = VmInstanceConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/vm-instances/{vmInstanceUuid}/actions",
        isAction = true,
        responseClass = APIMigrateVmEvent.class,
        method = HttpMethod.PUT
)
public class APIMigrateVmMsg extends APIMessage implements VmInstanceMessage {

    @APIParam(resourceType = VmInstanceVO.class, checkAccount = true, operationTarget = true)
    private String vmInstanceUuid;

    @APIParam(required = false, resourceType = HostVO.class)
    private String hostUuid;

    public void setVmInstanceUuid(String vmInstanceUuid) {
        this.vmInstanceUuid = vmInstanceUuid;
    }

    public String getVmUuid() {
        return vmInstanceUuid;
    }

    public void setVmUuid(String vmInstanceUuid) {
        this.vmInstanceUuid = vmInstanceUuid;
    }

    public String getHostUuid() {
        return hostUuid;
    }

    public void setHostUuid(String hostUuid) {
        this.hostUuid = hostUuid;
    }

    @Override
    public String getVmInstanceUuid() {
        return getVmUuid();
    }
 
    public static APIMigrateVmMsg __example__() {
        APIMigrateVmMsg msg = new APIMigrateVmMsg();
        msg.vmInstanceUuid = uuid();
        msg.hostUuid = uuid();
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                ntfy("Migrated").resource(vmInstanceUuid, VmInstanceVO.class.getSimpleName())
                        .messageAndEvent(that, evt).done();
            }
        };
    }

}
